﻿using System.Configuration;
using System.Reflection;
using System.Runtime.InteropServices;
using Autofac;
using AutomatedAcceptanceTests.Test;
using AutomatedAcceptanceTests.WorkFlows;
using ServiceInterfaces;
using Services;

namespace AutomatedAcceptanceTests.IOC
{
    public class InitAutofac
    {
        public static IContainer Init()
        {
            var builder = new ContainerBuilder();

            var connString = ConfigurationManager.ConnectionStrings["BBOS"].ConnectionString;
            var sdfConnString = ConfigurationManager.ConnectionStrings["ADF"].ConnectionString;

            var servicesAssembly = Assembly.Load("Services");
            builder.RegisterAssemblyTypes(servicesAssembly).AsImplementedInterfaces();

            var docProcessingRepositoryAssembly = Assembly.Load("DocProcessingRepository");
            builder.RegisterAssemblyTypes(docProcessingRepositoryAssembly).AsImplementedInterfaces().WithParameter(new NamedParameter("connectionString", connString));

            builder.RegisterType<UserService>().As<IUserService>().InstancePerDependency();

            builder.RegisterType<DocProcessingRepository.Repositories.PackStoreRepository>()
                .As<DocProcessingRepository.Interfaces.IPackStoreRepository>()
                .WithParameter(new NamedParameter("connectionString", sdfConnString));

            //            builder.RegisterType<Test.Test>().As<ITest>();
            //            builder.RegisterType<TestTwo>().As<ITestTwo>();

            var identityAssembly = Assembly.Load("IdentityWrapper");
            builder.RegisterAssemblyTypes(identityAssembly)
                .AsImplementedInterfaces()
                .WithParameter(new NamedParameter("connectionString", connString));



            builder.RegisterType<UserAccountWorkFlow>().As<UserAccountWorkFlow>();
            return builder.Build();
            
        }
    }
}